package com.milkTeaServer.controller;

import com.milkTeaServer.bean.MilkTea;
import com.milkTeaServer.dao.MilkTeaDao;
import com.milkTeaServer.dao.OrderDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/milkTea")
public class MilkTeaController {
    @Autowired
    MilkTeaDao dao;

    @RequestMapping("/list")
    @ResponseBody
    public Map getMilkTeaList() {
        Map map = new HashMap();
        List<MilkTea> milkTeaList = dao.findAll();
        if (milkTeaList != null) {
            map.put("success", true);
            map.put("massage", "获取列表成功");
            map.put("data", milkTeaList);
        } else {
            map.put("success", false);
            map.put("massage", "获取列表失败");
            map.put("data", null);
        }
        return map;
    }

    @RequestMapping("/findById")
    @ResponseBody
    public Map findTea(@RequestBody MilkTea milkTea) {
        Map map = new HashMap();
        List<MilkTea> milkTeaList = dao.findTeaById(milkTea.getId());
        if (milkTeaList != null) {
            map.put("success", true);
            map.put("massage", "获取奶茶成功");
            map.put("data", milkTeaList.get(0));
        } else {
            map.put("success", false);
            map.put("massage", "获取奶茶失败");
            map.put("data", null);
        }
        return map;
    }
}
